using System;

namespace Sedna.Core.Messaging
{
	public interface IMessageSession
	{
		/// <summary>
		/// sends a Message to a default preconfigured EndPoint
		/// for the underlying session
		/// </summary>
		/// <param name="payload">
		/// an object that represents a Message. 
		/// The format of the object must be acceptable for the underlying 
		/// session (i.g. if it is a distributed queue it must be Serializable) 
		/// The object is wrapped into an instance of an IMessage. 
		/// If an object is an instance of an IMessage, then that 
		/// object is not wrapped and is send as is
		/// </param>
		void Send(object payload);

		/// <summary>
		/// sends a Message to a specified EndPoing.
		/// the underlying session must recognize that EndPoint. If an EndPoint
		/// cannot be recognized, and exception is thrown
		/// </summary>
		/// <param name="endPoint">destination EndPoint</param>
		/// <param name="payload">
		/// an object that represents a Message. 
		/// The object is wrapped into an instance of an IMessage. 
		/// If an object is an instance of an IMessage, then that object 
		/// is not wrapped and is send as is
		/// </param>
		void Send(IEndPoint endPoint, object payload);

		/// <summary>
		/// sends an instance of a well-formed IMessage
		/// </summary>
		/// <param name="message">
		/// an instance of a well-formed IMessage 
		/// (i.e. containing all necessary headers and a payload)
		/// </param>
		void Send(IMessage message);

		/// <summary>
		/// tries to receive a Message from an underlying EndPoint.
		/// the method blocks untill a Message is ready to be received
		/// </summary>
		/// <returns>an instance of a Message</returns>
		IMessage Receive();


		/// <summary>
		/// tries to receive a Message from an underlying EndPoint.
		/// the method blocks untill either a Message is ready to be received or a timeout is elapsed.
		/// in the latter case the method returns null;
		/// </summary>
		/// <param name="timeout"></param>
		/// <returns></returns>
		IMessage Receive(int timeout);
	}
}
